package com.api.shopapi.mapper;

import com.api.shopapi.entity.JKXuetang;
import com.api.shopapi.entity.dto.JKXuetangDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface JKXuetangMapper {

    @Insert("insert into jk_xuetang (JKXuetangCode,UserCode,XueTang,FromType,InspectTime,CreateTime) values " +
            "(#{jkXuetang.JKXuetangCode},#{jkXuetang.UserCode},#{jkXuetang.XueTang},#{jkXuetang.FromType}," +
            "#{jkXuetang.InspectTime},#{jkXuetang.CreateTime})")
    int insert(@Param("jkXuetang") JKXuetang jkXuetang);


    @Update("update jk_xuetang set UserCode=#{jkXuetang.UserCode},XueTang=#{jkXuetang.XueTang}," +
            "FromType=#{jkXuetang.FromType},InspectTime=#{jkXuetang.InspectTime},CreateTime=#{jkXuetang.CreateTime} " +
            "where JKXuetangCode=#{jkXuetang.JKXuetangCode}")
    int update(@Param("jkXuetang") JKXuetang jkXuetang);

    @Delete("delete from jk_xuetang where JKXuetangCode=#{jKXuetangCode}")
    int delete(@Param("jKXuetangCode") String jKXuetangCode);

    @Select("select * from jk_xuetang where JKXuetangCode=#{jKXuetangCode} limit 1")
    JKXuetang getByJKXuetangCode(@Param("jKXuetangCode") String jKXuetangCode);

    @Select("select * from jk_xuetang where UserCode=#{userCode} and InspectTime between #{startTime} and #{endTime} order by InspectTime desc")
    List<JKXuetang> getPageList(@Param("userCode") String userCode,@Param("startTime") String startTime,@Param("endTime") String endTime);


    @Select("<script>" +
            "select jx.*,u.Name as userName from jk_xuetang jx left join user u on jx.UserCode=u.UserCode " +
            "where u.GovernmentCode=#{governmentCode} " +
            "<if test ='name !=null and name!=\"\" '>" +
            "and u.Name like concat('%',#{name},'%') " +
            "</if>" +
            "and jx.InspectTime between #{startTime} and #{endTime} " +
            "order by jx.InspectTime desc" +
            "</script>")
    List<JKXuetangDTO> getAdmPageList(@Param("name") String name, @Param("governmentCode") String governmentCode, @Param("startTime") String startTime, @Param("endTime") String endTime);




}
